String.fromCharCode()

您所在的位置:网站首页 ascii table results String.fromCharCode()

String.fromCharCode()

2023-03-07 03:10| 来源: 网络整理| 查看: 265

In UTF-16, the most common characters can be represented by a single 16-bit value (i.e. a code unit). However, this set of characters, known as the Base Multilingual Plane (BMP), is only 1/17th of the total addressable Unicode code points. The remaining code points, in the range of 65536 (0x010000) to 1114111 (0x10FFFF) are known as supplementary characters. In UTF-16, supplementary characters are represented by two 16-bit code units, known as surrogates, that were reserved for this purpose. A valid combination of two surrogates used to represent a supplementary character is known as a surrogate pair.

Because fromCharCode() only works with 16-bit values (same as the \u escape sequence), a surrogate pair is required in order to return a supplementary character. For example, both String.fromCharCode(0xD83C, 0xDF03) and \uD83C\uDF03 return code point U+1F303 "Night with Stars".

While there is a mathematical relationship between the supplementary code point value (e.g. 0x1F303) and both surrogate values that represent it (e.g., 0xD83C and 0xDF03), it does require an extra step to either calculate or look up the surrogate pair values every time a supplementary code point is to be used. For this reason, it's more convenient to use String.fromCodePoint(), which allows for returning supplementary characters based on their actual code point value. For example, String.fromCodePoint(0x1F303) returns code point U+1F303 "Night with Stars".



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3